package com.prd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.config.LoginInterceptor;
import com.prd.mapper.EntNoticeRecipientMapper;
import com.prd.model.EntNoticeRecipient;
import com.prd.model.LoginUser;
import com.prd.service.EntNoticeRecipientService;
import com.prd.util.UserInfoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EntNoticeRecipientServiceImpl extends ServiceImpl<EntNoticeRecipientMapper, EntNoticeRecipient> implements EntNoticeRecipientService {

    @Autowired
    private EntNoticeRecipientMapper entNoticeRecipientMapper;

    @Override
    public int insertInfo(EntNoticeRecipient entNoticeRecipient) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), true), entNoticeRecipient);
        return entNoticeRecipientMapper.insert(entNoticeRecipient);
    }

    @Override
    public int updateInfo(EntNoticeRecipient entNoticeRecipient) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), false), entNoticeRecipient);
        return entNoticeRecipientMapper.updateById(entNoticeRecipient);
    }
}
